package de.gameduell.framework.gui.animation {
	import fl.transitions.TweenEvent;

	import de.gameduell.framework.gui.animation.Tweenable;

	import flash.geom.Point;

	/**
	 * @author cbra
	 */
	public class PositionTween extends CombinedTween implements Tweenable {
	
		private var xTween:GDTween;
		private	var yTween:GDTween;
		/**
		 * @param tweenedObject  the object that will be tweened
		 * @param EaseType		 easytype for the tween
		 * @param startPoint     the point from wich the animation starts
		 * @param endPoint		 the point where the animation finishs
		 * @param useSeconds	 flag to asign if the animation is timebased or framebased
		 */
		public function PositionTween(tweenedObject:Object,EaseType:Function, startPoint:Point, endPoint:Point, duration:Number, useSeconds:Boolean) {
			super();
			xTween = new GDTween(tweenedObject, "x", EaseType, startPoint.x, endPoint.x, duration, useSeconds);
			yTween = new GDTween(tweenedObject, "y", EaseType, startPoint.y, endPoint.y, duration, useSeconds);
			xTween.addEventListener(TweenEvent.MOTION_CHANGE, dispatchMotionChange);
			addTween(xTween);
			addTween(yTween);
		}
		
		private function dispatchMotionChange(event:TweenEvent):void{
			dispatchEvent(new TweenEvent(event.type, event.time, event.position, event.bubbles, event.cancelable));
		}
		
		public function set finish(endPoint:Point):void{
			xTween.finish = endPoint.x;
			yTween.finish = endPoint.y;
		}
		
		public function get obj():Object{
			return xTween.obj;
		}
	}
}
